# # # 思考:如果创建一个字符串I'm Tom?
# #
# # print("I'm Tom")
# # print('I\'m Tom')
# #
# # str1 = """
# # 你好
# # 再见
# # """
#
#
# str1 = "abcdefg"
# # 根据下标查找某个元素, 下标从0开始
# print(str1[0])
# print(str1[3])
# print(str1[-1])
# # 切片语法: 序列[开始:结束:步长]
# # 顾头不顾尾
# name = "abcdefg"
# # print(name[2:5:1])
# # print(name[2:5])
# # print(name[:5])
# # print(name[2:])
# # print(name[:])
# # print(name[::3])
# print(name[::-2])
# # 步长为负数
# # 注意:步长如果为负数,则从开始位置向左取值,步长为负数需要注意开始和结束位置下标的关系
# print(name[5:2:-1])
# print(name[5:2:1])


# mystr = "hello world and supertest and chenghao and Python"
# # 字符串查找相关语法
# # 查找某个子串出现的位置:
# # 字符串.find(子串,开始,结束),找到第一个匹配项返回这个匹配项的开始位置下标,如果查询不到返回-1,开始和结束不写默认在整个字符串内查找
# print(mystr.find("and"))
# print(mystr.find("ands"))
# print(mystr.find("and", 13, 30))
# # 字符串.index(子串,开始,结束),到第一个匹配项返回这个匹配项的开始位置下标,如果查询不到报错,开始和结束不写默认在整个字符串内查找
# print(mystr.index("and"))
# print(mystr.index("and", 13, 30))
# # print(mystr.index("ands"))
# # 统计子串出现次数:字符串.count(子串,开始,结束)
# print(mystr.count("and"))
# print(mystr.count("and", 13, 100))
# print(mystr.count("ands", 13, 100))
# ---------------------------------------------
# print(mystr.rfind("and"))
# print(mystr.rindex("and"))
# =====================================================================
# mystr = "hello world and supertest and chenghao and Python"
# # 字符串是不可变数据类型
# # 字符串修改相关语法
# # 替换:字符串.replace(旧, 新, 次数)
# print(mystr.replace("and", "he"))
# print(mystr.replace("and", "he", 1))
# print(mystr)
# # 字符串分割: 字符串.split(分割字符),分割字符会被吃掉
# print(mystr.split("and"))
# # 字符串拼接:拼接字符.join(需要拼接的序列)
# list1 = ["aa", "bb", "cc", "dd"]
# print("==>".join(list1))
# # 功能性修改
# mystr = "hello world and supertest and chenghao and Python"
# # 将字符串内所有字母全变成大写:
# print(mystr.upper())
# # 将字符串内所有字母全变成小写:
# print(mystr.lower())
# # 将整个字符串首字母大写,其他小写
# print(mystr.capitalize())
# # 将每个单词首字母大写
# print(mystr.title())
# mystr = "   hello world and supertest and chenghao and Python    "
# # 去除字符串两面的指定字符,默认去除空格
# print(mystr)
# print(mystr.strip())
# print(mystr.strip("nh "))
# # 去除字符串左面的指定字符
# print(mystr.lstrip())
# # 去除字符串右面的指定字符
# print(mystr.rstrip())
# # -----------------------------
# # 补全字符
# str1 = "hello"
# # 居中补全
# print(str1.center(20, "+"))
# # 靠左补全
# print(str1.ljust(20, "-"))
# # 靠右补全
# print(str1.rjust(20, "-"))
# ===================================================================
mystr = "hello world and supertest and chenghao and Python"
# 字符串判断相关语法
# 判断字符串是否以指定的字符开始
print(mystr.startswith("hello"))
print(mystr.startswith("Hello"))
# 判断字符串是否以指定字符结尾
print(mystr.endswith("Python"))
str1 = "he你好llo"
str2 = "hello123"
str3 = "123456"
str4 = " "
# 判断字符串是否全由字母组成
print(str1.isalpha())
# 判断字符串是否全由数字组成
print(str3.isdigit())
# 判断字符串是否全由字母或者数字组成
print(str2.isalnum())
# 判断字符串是否全由空白字符组成
print(str4.isspace())
